package org.example.sulotion;

public class 加一 {
    public static void main(String[] args) {

//        int[] nums={1,2,3};
//        int[] nums={9,8,7,6,5,4,3,2,1,0};
        int[] nums={8,9,8,9,9};
        int[] ints = plusOne(nums);
        for (int i : ints) {
            System.out.println(i);

        }


    }



    //99 100
    //89 90
    public static int[] plusOne(int[] digits) {
        if(digits[0]==0){
            return new int[] {1};
        }
/*
        int n = digits.length;
        for (int i = n - 1; i >= 0; i--) {
            if (digits[i] == 9) {
                digits[i] = 0;
            } else {
                digits[i] += 1;
                return digits;
            }
        }
        int[] ans = new int[n + 1];
        ans[0] = 1;
        return ans;
*/
        int len=digits.length;
        for (int i = len-1; i >= 0 ; i--) {
            if(digits[i] == 9){
                digits[i]=0;
            }else {
                digits[i]=digits[i]+1;
                return digits;
            }

        }
        int[] ints = new int[len + 1];
        ints[0]=1;
        return ints;
    }



/*        StringBuffer buffer = new StringBuffer();
        long value= 0;
        for (int i = 0; i <digits.length ; i++) {
            buffer.append(String.valueOf(digits[i]));
        }
        String s = buffer.toString().trim();
        if(!"".equals(s) && s != null){
            value = Long.parseLong(s.trim());
        }

        value=value+1;
        String res = String.valueOf(value);
        int length = res.length();
        int[] ints = new int[length];
        for (int i = 0; i <length ; i++) {
            ints[i]=Integer.valueOf(res.charAt(i)-48);
        }
        System.out.println(value+"=============");*/

}
